package com.ciis.system.relation.service.impl;

import com.ciis.system.relation.domain.TSysUserRole;
import com.ciis.system.relation.mapper.ITSysUserRoleMapper;
import com.ciis.system.relation.service.ISysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: zhangdajun
 * Date: 14-6-1
 * Time: 下午10:27
 * To change this template use File | Settings | File Templates.
 */
@Service("userRoleService")
public class SysUserRoleServiceImpl implements ISysUserRoleService {

    @Autowired
    ITSysUserRoleMapper userRoleMapper;

    @Override
    public void save(TSysUserRole userRole) throws Exception {
        userRoleMapper.save(userRole);
    }

    @Override
    public void delete(TSysUserRole userRole) throws Exception {
        userRoleMapper.delete(userRole);
    }

    @Override
    public void deleteByUId(String userId) throws Exception {
        userRoleMapper.deleteByUId(userId);
    }

    @Override
    public List<TSysUserRole> getUserRolesByUId(String userId) throws Exception {
        return userRoleMapper.getUserRolesByUId(userId);
    }

    @Override
    public List<TSysUserRole> getUserRolesByRId(String roleId) throws Exception {
        return userRoleMapper.getUserRolesByRId(roleId);
    }

    @Override
    public HashMap<String, String> getRoleMapByUId(String userId) throws Exception {
        HashMap<String, String> rst = new HashMap<String, String>();
        List<TSysUserRole> userRoleList = getUserRolesByUId(userId);
        for(TSysUserRole userRole : userRoleList){
            rst.put(userRole.getRole_id(),userRole.getRole_id());
        }
        return rst;
    }
}
